<template>
	<view class="wrap">
		<view class="checkboxContent">
			<view @click="selectList(index)" :class="[index === list.length - 1 ? 'border-bottom0' : '', 'list']" v-for="(item, index) in list" :key="index">
				<i-icon
					:icon="item.checked ? 'icongouxuan' : 'icontuoyuan'"
					:color="item.checked ? '' : '#f3f3f3'"
					:type="item.checked ? 'multiple' : 'single'"
					class="mr-5 middle"
					size="40rpx"
				></i-icon>
				{{ item.name }}
			</view>
		</view>
		<view class="fixedBottomBtn">
			<view class="width-35 left" @click="selectAllFun">
				<i-icon
					:icon="selectAll ? 'icongouxuan' : 'icontuoyuan'"
					:color="selectAll ? '' : '#f3f3f3'"
					:type="selectAll ? 'multiple' : 'single'"
					class="mr-5 middle"
					size="40rpx"
				></i-icon>
				<text :class="selectAll ? '' : 'color-fff'">全选</text>
			</view>
			<view :class="['width-65', isChecked ? 'right' : 'bge1']" @click="OrderCarDispose">确认</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			list: [
				{ checked: false, name: '户口本', val: 'residence' },
				{ checked: false, name: '驾驶证', val: 'driving_license' },
				{ checked: false, name: '结婚证', val: 'marriage_license' },
				{ checked: false, name: '微信/支付宝流水', val: 'wechat_alipay_record' },
				{ checked: false, name: '银行流水', val: 'account_statement' },
				{ checked: false, name: '购房合同', val: 'house_purchase_contract' }
			],
			selectAll: false,
			isChecked: false,
			id:''
		};
	},
	onLoad(options) {
		this.id=options.id
	},
	methods: {
		selectList(index) {
			this.list[index].checked = !this.list[index].checked;
			for (var i = 0; i < this.list.length; i++) {
				let it = this.list[i];
				if (it.checked) {
					this.isChecked = true;
					return;
				} else {
					this.isChecked = false;
				}
			}
		},
		selectAllFun() {
			this.selectAll = !this.selectAll;
			if (this.selectAll) {
				this.list.forEach((it, index) => {
					this.list[index].checked = true;
				});
				this.isChecked = true;
			} else {
				this.list.forEach((it, index) => {
					this.list[index].checked = false;
				});
				this.isChecked = false;
			}
		},
		// 订单处理
		async OrderCarDispose() {
			//type 0、通过 1、未通过 2、补充资料
			if (this.isChecked) {
				uni.showLoading({
					title: '加载中'
				});
				let data = {
					oid: this.id,
					storeid: this.$store.state.userInfoDetail.store.storeId,
					type: 2
				};
				this.list.forEach(it => {
					if (it.checked) {
						data[it.val] = true;
					}
				});
				// console.log(data);
				const res = await this.$api.carOrder.OrderCarDispose(data);
				try {
					uni.hideLoading();
					console.log(res);
					uni.showToast({
						title: '操作成功',
						duration: 2000,
						icon: 'success'
					});
					setTimeout(function() {
						uni.redirectTo({
							url: '/pages_order/orderAdmin/orderAdmin'
						});
					}, 2000);
				} catch (err) {
					uni.hideLoading();
					console.log(err);
					uni.showToast({
						title: '请稍后重试',
						duration: 2000,
						icon: 'none'
					});
				}
			} else {
				uni.showToast({
					title: '请选择资料类型',
					duration: 2000,
					icon: 'none'
				});
			}
		}
	}
};
</script>

<style scoped lang="scss">
.wrap {
	width: 100%;
	height: 100vh;
	padding-top: 20rpx;
	background: #f5f5f5;
	.checkboxContent {
		width: 95%;
		background-color: #fff;
		padding: 1%;
		margin: auto;
		border-radius: 20rpx;
	}
}
.width-65 {
	width: 65%;
}
.list {
	width: 98%;
	padding: 16rpx 2%;
	margin: auto;
	background-color: #fff;
	border-bottom: 1rpx solid #f3f3f3;
}
.color-fff {
	color: #e6e6e6;
}
.border-bottom0 {
	border-bottom: 0rpx;
}
.mr-5 {
	margin-right: 10rpx;
}
.fixedBottomBtn {
	width: 100%;
	height: 100rpx;
	line-height: 100rpx;
	text-align: center;
	position: fixed;
	bottom: 0rpx;
	background-color: #fff;
	display: flex;
	font-size: 32rpx;
	.left {
		background: #333333;
		color: #fdd421;
		.checkboxBtn {
			border-radius: 50%;
		}
	}
	.right {
		background: linear-gradient(-90deg, #fdd421, #ffe23e);
	}
	.bge1 {
		background: #e1e1e1;
	}
}
</style>
